<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    <title>评论管理</title>
    <link rel="shortcut icon" href="/image/favicon.ico"/>
    <!-- Font Awesome -->
    <link href="https://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
    <!-- Bootstrap core CSS -->
    <link href="https://cdn.bootcss.com/bootstrap/4.0.0/css/bootstrap.css" rel="stylesheet">
    <!-- Material Design Bootstrap -->
    <link href="/css/mdb.css" rel="stylesheet">
    <link href="/css/style.css" rel="stylesheet">
    <link href="/css/toastr.css" rel="stylesheet">
</head>
<style>
    .table tbody tr td {
        vertical-align: middle;
        padding: 5px;
        color: #87ed92;
    }
    .table tbody tr td span{
        padding: 5px;
        white-space: pre-wrap;
    }
    .table th {
        font-size: large;
    }
</style>
<body class="creative-lp">

<header>
    <!-- 后台顶部导航 -->
    <nav th:replace="~{admin/common :: nav}"></nav>
</header>

<!-- /.Main Container -->
<div class="container">
    <div class="row pt-4">
        <!-- Content -->
        <div class="col-lg-12">
            <!-- Books Grid -->
            <section class="section pt-4">

                <!-- Grid row -->
                <div class="row">

                    <div class="widget-body no-padding">
                        <table id="dt-table"
                               class="table table-striped table-bordered table-hover"
                               style="width: 100%">
                            <thead>
                            <tr></tr>
                            <tr class="col-lg-12 col-md-6 mb-4 text-center">
                                <th>头像</th>
                                <th>昵称</th>
                                <th>邮箱</th>
                                <th>内容</th>
                                <th>回复</th>
                            </tr>
                            </thead>
                            <tbody>
                            <tr class="col-lg-12 col-md-6 mb-4" th:each="comment : ${comments}">

                                <td><img th:src="${comment.avatar}" class="mx-auto d-block" alt="" style="max-height: 80px;"></td>
                                <td style="text-align: center"><span class="badge badge-info mb-2" th:text="${comment.id}" ></span></td>
                                <td style="text-align: center"><span class="badge badge-info mb-2" th:text="${comment.name}"></span></td>
                                <td style="text-align: center"><span class="badge badge-info mb-2" th:text="${comment.email}"></span></td>
                                <td><span class="badge badge-info mb-6" th:utext="${comment.content}"  style="text-align: left;line-height: 18px;"></span></td>

                                <td>
                                    <a class="btn blue-gradient btn-rounded btn-sm font-weight-normal"
                                       data-toggle="modal" data-target="#shareModal" th:onclick="'javascript:replayCommen(\''+${comment.id}+'\');'">
                                        <i class="fa fa-wechat"></i>&nbsp;回复</a>
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </div>

                </div>
                <!--Grid row-->

            </section>
            <!-- /.Products Grid -->

        </div>
        <!-- /.Content -->

    </div>
</div>
<!-- /.Main Container -->

<!-- 留言回复窗口 -->
<div class="modal fade" id="shareModal" tabindex="-1" role="dialog" aria-labelledby="shareModalLabel"
     aria-hidden="true">
    <div class="modal-dialog modal-notify modal-success" role="document">
        <!--Content-->
        <div class="modal-content">
            <!--Header-->
            <div class="modal-header">
                <p class="heading lead">留言回复</p>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true" class="white-text">×</span>
                </button>
            </div>
            <!--Body-->
            <div class="modal-body">
                <div class="text-center">
                    <!-- 对号的动画效果 -->
                    <!-- <i class="fa fa-check fa-3x mb-3 animated rotateIn"></i>-->
                    <div class="col-md-12 col-xl-12">
                        <form>
                            <!--Grid row-->
                            <div class="row">
                                <!--Grid column-->
                                <div class="col-md-12">
                                    <div class="md-form">
                                        <input type="hidden" id="id"></input>
                                        <textarea type="text" id="content" class="md-textarea form-control"
                                                  rows="3"></textarea>
                                        <label for="content">回复内容</label>
                                    </div>
                                </div>
                            </div>
                            <!--Grid row-->
                        </form>
                    </div>
                </div>
            </div>

            <!--Footer-->
            <div class="modal-footer justify-content-center">
                <a type="button" class="btn btn-success waves-effect waves-light" onclick="submitContent()"
                   data-dismiss="modal">
                    <i class="fa fa-check ml-1"></i>
                    确定
                </a>
                <a type="button" class="btn btn-outline-success waves-effect" data-dismiss="modal">
                    <i class="fa fa-times l-1"></i>
                    取消
                </a>
            </div>
        </div>
        <!--/.Content-->
    </div>
</div>

<!-- 返回顶部 -->
<section>
    <div class="fixed-action-btn" style="bottom: 45px; right: 24px;">
        <a class="btn-floating btn-lg purple-gradient" style="display:none;" id="goTop">
            <i class="fa fa-arrow-up" aria-hidden="true"></i>
        </a>
    </div>
</section>

<!-- 网站底部 -->
<footer th:replace="~{common :: footer}"></footer>
<!-- /网站底部 -->

<!-- JQuery -->
<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
<!-- Bootstrap core JavaScript -->
<script src="https://cdn.bootcss.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<!-- MDB core JavaScript -->
<script src="https://cdn.bootcss.com/mdbootstrap/4.5.0/js/mdb.min.js"></script>
<script src="https://cdn.bootcss.com/toastr.js/latest/toastr.min.js"></script>

<script>
    //Animation init
    new WOW().init();

    // 返回顶部
    $(function () {
        $(window).scroll(function () {
            if ($(window).scrollTop() > 500) {
                $("#goTop").fadeIn(200);
            }
            else {
                $("#goTop").hide(200);
            }
        });
        $("#goTop").click(function () {
            $('html,body').animate({'scrollTop': 0}, 500);
        });
    });

    function replayCommen(id) {
        $('#id').val(id);
    }

    /**
     * 回复用户留言
     */
    function submitContent() {
        var id = $("#id").val();
        var content = $("#content").val();
        if (content.trim().length === 0) {
            toastr.error("请填写回复内容 ！");
            return;
        }
        $.post("/admin/comment_replay", {
            id: id,
            content: content
        }, function (response) {
            if (response.code === 0) {
                $('#id').val("");
                $('#content').val('');
                toastr.success("回复成功！");
                var send = function () {
                    window.location.reload();
                };
                setTimeout(send, 1000);
            } else {
                toastr.error("发送失败，请检查后台日志信息！");
            }
        });
        return false;
    }
</script>

</body>
</html>